/**
 * $RCSfile$
 * $Revision$
 * $Date$
 * $Source$
 * $Author$
 */
package pl.edu.agh.loganalizator.model;

import java.util.ArrayList;

public class ColumnModel {

  ArrayList<Column> column;

  public ColumnModel(String def) {
    String[] colArray = getRowStringArray(def);
    column = new ArrayList<Column>(colArray.length);
    for (int i = 0; i < colArray.length; i++) {
      column.add(new Column(colArray[i]));
    }
  }

  public Row getRowValue(String row) throws Exception {
    if (row == null || row.length() == 0)
      throw new Exception();
    Row roww = new Row();
    String[] colArray = getRowStringArray(row);
    for (int i = 0; i < colArray.length; i++) {
      roww.add(column.get(i), colArray[i]);
    }
    return roww;
  }

  private String[] getRowStringArray(String val) {
    String splitString = val.substring(1, val.length() - 1);
    String[] colArray = splitString.split("\",\"");
    return colArray;
  }

  public ArrayList<Column> getAvailableColumnCollection() {
    // TODO Auto-generated method stub
    System.out.println(column);
    return column;
  }
}
